﻿using System.Windows;
using Caliburn.Micro;

namespace PurchaseSales.Manage.Common
{
    public class WindowManagerHelper
    {
        public static bool GetFitWindowSize(DependencyObject obj)
        {
            return (bool)obj.GetValue(FitWindowSizeProperty);
        }

        public static void SetFitWindowSize(DependencyObject obj, object value)
        {
            obj.SetValue(FitWindowSizeProperty, value);
        }

        // Using a DependencyProperty as the backing store for FitWindowSize.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty FitWindowSizeProperty =
            DependencyProperty.RegisterAttached("FitWindowSize", typeof(bool), typeof(WindowManagerHelper),
            new PropertyMetadata(false, (o, args) =>
            {
                if (Execute.InDesignMode)
                    return;

                var window = Application.Current.Windows[0];//get shellView and set ShowDialogView's Size
                if (window != null)
                {
                    var child = o as Window;
                    if (child != null)
                    {
                        child.Width = window.ActualWidth;
                        child.Height = window.ActualHeight - 80;
                        child.Left = window.WindowState == WindowState.Maximized ? 0 : window.Left;
                        child.Top = (window.WindowState == WindowState.Maximized ? 0 : window.Top) + 80;
                    }
                }
            }));


    }
}
